// pages/myclubmanage/myclubmanage.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    tabarr: ["社团信息", "活动管理", "数据中心"],
    TabCur: 0,
    scrollLeft: 0,
    club: [],
    student: 100,
    male: 33,
    activeNames: ['1']
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    wx.setNavigationBarTitle({
      title: '我管理的社团',
    })
    const db = wx.cloud.database();
    const clubco = db.collection("club")
    var that = this
    that.setData({
      clubId: options.mymanageclubid
    })
    db.collection("event").where({
      host: options.mymanageclubid
    }).get().then(function(eveRes) {
      that.setData({
        events: eveRes.data
      })
    })
    clubco.where({
      _id: options.mymanageclubid
    }).get().then(
      function(res) {
        that.setData({
          club: res.data[0]
        })
      }
    )
    var ctx = wx.createCanvasContext('customCanvas')
    ctx.setFillStyle('#12CEDD')
    ctx.fillRect(10, 10, 280 * that.data.male / that.data.student, 20)
    ctx.draw()
    ctx.setFillStyle('pink')
    ctx.fillRect(10 + 280 * that.data.male / that.data.student, 10, 280 * (1 - that.data.male / that.data.student), 20)
    ctx.draw(true)
  },

  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 1) * 60
    })
  },

  gotoCreateEvent: function(e) {
    var that = this
    wx.navigateTo({
      url: '../../pages/createvent/createvent?id=' + that.data.clubId
    })
  },


  gotoEdit: function() {
    wx.navigateTo({
      url: "../../pages/clubinfoedit/clubinfoedit?clubid=" + this.data.club._id
    })
  },
  onChange(event) {
    this.setData({
      activeNames: event.detail
    });
  }
})